﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace THenu.TinyHourseLib.DesignPattern.Structural_Patterns.Adapter_Pattern
{
    /// <summary>
    /// 适配器模式 -> 调用示例
    /// </summary>
    public class AdapterPattern : IPatternDemonstrate
    {
        /// <summary>
        /// 结构代码
        /// </summary>
        public void StructuralCode()
        {
            // Create adapter and place a request
            Target iTarget = new Adapter();
            iTarget.Request();
        }
        /// <summary>
        /// 描述信息
        /// </summary>
        /// <returns></returns>
        public string PatternDescription()
        {
            string strDescription = @"
Convert the interface of a class into another interface clients expect. 
Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

Participants

    The classes and objects participating in this pattern are:

Target   (ChemicalCompound)
defines the domain-specific interface that Client uses.
Adapter   (Compound)
adapts the interface Adaptee to the Target interface.
Adaptee   (ChemicalDatabank)
defines an existing interface that needs adapting.
Client   (AdapterApp)
collaborates with objects conforming to the Target interface.";
            return strDescription;
        }
        /// <summary>
        /// 演示例子
        /// </summary>
        public void RealWorldExample()
        {
            // Non-adapted chemical compound
            Compound unknown = new Compound("Unknown");
            unknown.Display();

            // Adapted chemical compounds
            Compound water = new RichCompound("Water");
            water.Display();

            Compound benzene = new RichCompound("Benzene");
            benzene.Display();

            Compound ethanol = new RichCompound("Ethanol");
            ethanol.Display();

            // Wait for user
            Console.ReadLine();
        }
    }
}
